
    /**  
    * @Title: LogStorageLockServiceImpl.java
    * @Package com.efast.cafe.commponent.log.service.impl
    * @Description: TODO(用一句话描述该文件做什么)
    * @author Administrator
    * @date 2018年9月5日
    * @version V1.0  
    */
    
package com.efast.cafe.commponent.log.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import com.efast.cafe.commponent.log.ext.CafeLogger;
import com.efast.cafe.commponent.log.ext.CafeLoggerFactory;
import com.efast.cafe.commponent.log.service.LogStorageLockService;

/**
    * @ClassName: LogStorageLockServiceImpl
    * @Description: TODO(这里用一句话描述这个类的作用)
    * @author Administrator
    * @date 2018年9月5日
    *
    */
@Service
public class LogStorageLockServiceImpl implements LogStorageLockService {

	CafeLogger logger = CafeLoggerFactory.getLogger(getClass());
	
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	
	/* (非 Javadoc)
	* 
	* 
	* @param key
	* @param value
	* @return
	* @see com.efast.cafe.commponent.log.service.LogStorageLockService#lockStorage(java.lang.String, java.lang.String)
	*/

	@Override
	public boolean lockStorage(String key, String value) {
		boolean result = false;
        try {
            ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();
	            return operations.setIfAbsent(key, value);
        } catch (Exception e) {
        	logger.warn("获取锁失败", e);
        }
        return result;
	}

}
